package com.bkhc.order.repository;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bkhc.common.util.response.ResultJson;
import com.bkhc.common.vo.CustomerVo;
import com.bkhc.common.vo.GoodsSpecVo;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

@Component
public class ProductRepository {

    @Lazy
    @Autowired
    private RestTemplate restTemplate;

    public Map<String,Double> queryPrice(String instanceCode,String brandCode,String priceVersion){
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/PRODUCT/service/instance/queryPrice?instanceCode="+instanceCode+"&brandCode="+brandCode+"&priceVersion="+priceVersion;
        ResultJson  result = restTemplate.postForObject(url, null, ResultJson.class);
        Map map = (Map) result.getData();
        return map;
    }

    public Map getPartnerByBrandCodeAndProductCode(String brandCode, String productCode) {
            String serviceName = "PRODUCT-APP";
            String url = "http://" + serviceName + "/product/common/getPartnerByBrandProduct?productCode="+productCode+"&brandCode="+brandCode;
            Map map = restTemplate.getForObject(url,  Map.class);
            return map;
    }
    public List<GoodsSpecVo> getGoodsSpecbyGoodsCode(List<String> goodsCodeIn) {
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/getGoodsSpecByGoodsCode";
        List<GoodsSpecVo> list = (List<GoodsSpecVo>) restTemplate.postForObject(url,goodsCodeIn,ResultJson.class).getData();
        String s = JSON.toJSONString(list);
        list = JSON.parseArray(s,GoodsSpecVo.class);
        return list;
    }
}
